package com.clob.properties;

import com.clob.exception.PropertiesException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public abstract class AbstractLoadProperties implements LoadProperties{

    /**
     * 配置文件名字
     */
    private String source;

    /**
     * 属性文件 properties
     */
    private Properties properties;

    AbstractLoadProperties(String source){
        this.source = source;
        initProperties();
    }

    @Override
    public void initProperties() {
        InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(source);
        try {
            properties = new Properties();
            properties.load(inputStream);
        } catch (IOException e) {
            throw new PropertiesException("初始化Properties异常");
        }
    }

    @Override
    public String getProperty(String proName) {
        return properties.getProperty(proName);
    }

}
